<%@ page language="java" import="java.util.*" pageEncoding="utf-8"
         contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://"
          + request.getServerName() + ":" + request.getServerPort()
          + path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>我的租借 - 徐二组体育馆网上系统</title>
  <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
  <link href=" ${pageContext.request.contextPath}/static/css/nav.css" rel="stylesheet" type="text/css"/>
  <script src="${pageContext.request.contextPath}/static/js/nav.js" type="text/javascript"></script>
  <script src="${pageContext.request.contextPath}/static/js/focus.js" type="text/javascript"></script>
  <link href=" ${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet" type="text/css"/>
  <link href=" ${pageContext.request.contextPath}/static/css/usercenter.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<%@ include file="../header.jsp" %>
<div id="main">
  <div id="row_1">
    <table id="book-list" cellspacing="2px">
      <tr>
        <th scope="col">场地编号</th>
        <th scope="col">起始时间</th>
        <th scope="col">结束时间</th>
        <th scope="col">资费</th>
        <th scope="col" class="book">操作</th>
      </tr>
      <c:forEach items="${books}" var="list">
        <tr>
          <td>${list.getPlaceID()}</td>
          <td>${list.getStartTime()}</td>
          <td>${list.getEndTime()}</td>
          <td>0_0</td>
          <td class="align-center">
            <button
                    onclick="updateBook(this,'${list.getPlaceID()}','${list.getStartTime()}','${list.getEndTime()}')">
              续租
            </button>
            <button
                    onclick="deleteBook(this,'${list.getPlaceID()}','${list.getStartTime()}','${list.getEndTime()}')">
              删除
            </button>
          </td>
        </tr>
      </c:forEach>
    </table>
  </div>
</div>
<script>
  var def = "5";
  function updateBook(obj, placeID, startTime, endTime) {
    if (confirm("你确定续租吗？")) {
      $.ajax({
        url: "${pageContext.request.contextPath}/book/updateBook",
        type: "post",
        dataType: "json",
        data: {
          "startTime": startTime,
          "endTime": endTime,
          "placeID": placeID
        }
      })
    }
  }
  function deleteBook(obj, placeID, startTime, endTime) {

    if (confirm("你確定刪除嗎？")) {
      $.ajax({
        url: "${pageContext.request.contextPath}/book/deleteBook",
        type: "post",
        dataType: "json",
        data: {
          "startTime": startTime,
          "endTime": endTime,
          "placeID": placeID
        },
        async: false,
        success: function (data) {
          alert(data);
          $(obj).parent().parent().remove();
        }
      })
    }
  }
</script>
<%@ include file="../footer.jsp" %>
</body>
</html>
